<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "mall_product_specs".
 *
 * @property int $id
 * @property int $pid 对应的产品id
 * @property string $value 对应的属性值
 * @property int $stock 库存
 * @property string $price 价格
 * @property string $product_no 产品编码
 * @property string $img 图片
 * @property int $create_time
 */
class MallProductSpecs extends \yii\db\ActiveRecord
{
    //定义场景
    const SCENARIO_UPLOAD = 'upload';
    const SCENARIO_CREATE = 'create';

    public $file;

    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'mall_product_specs';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['value', 'stock', 'price', 'create_time'], 'required'],
            [['pid', 'stock', 'create_time'], 'integer'],
            [['price'], 'number'],
            [['product_no', 'img'], 'safe'],
            [['file'], 'file'],
            [['value'], 'string', 'max' => 20],
            [['product_no'], 'string', 'max' => 100],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'pid' => '产品ID',
            'value' => '属性值',
            'stock' => '库存',
            'price' => '价格',
            'product_no' => '产品编号',
            'create_time' => '创建时间',
            'img' => '规格图',
        ];
    }

    /**
     * 场景
     * @return array
     */
    public function scenarios()
    {
        $scenarios = parent::scenarios();
        $scenarios[self::SCENARIO_UPLOAD] = ['file'];
        $scenarios[self::SCENARIO_CREATE] = ['pid', 'value', 'stock', 'price', 'product_no', 'create_time', 'img'];
        return $scenarios;
    }
}
